#ifndef TYPE_C__
#define TYPE_C__

#include <stdlib.h>
#include "basic.h"

#if 0
import std.lib;
import basic;
#endif

enum TypeTag { CHAR, INT, VOID, ENUM, STRUCT, UNION, POINTER };
struct Type { enum TypeTag tag; void* internal; };

struct Type* allocateType(enum TypeTag tag, void* internal)
{
	struct Type* r = malloc(sizeof(struct Type));
	r->tag = tag;
	r->internal = internal;
	return r;
}

void freeType(struct Type* f)
{
	if(f == NULL) return;

	// If f->tag is CHAR, INT, or VOID, f->internal is null.

	if(f->tag == ENUM || f->tag == STRUCT || f->tag == UNION)
		freeName(f->internal);

	else if(f->tag == POINTER)
		freeType(f->internal);

	free(f);
}

#endif
